<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text" indent="no" />
  <xsl:param name="languageCode" />
  <!--
	if a label does not exist, which language to use as the default
-->
  <xsl:variable name="defaultLanguageCode">1033</xsl:variable>
  <xsl:template match="/grid"><![CDATA[<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:crm="http://mscrm" version="1.0" exclude-result-prefixes="msxsl crm">]]><![CDATA[<xsl:output method="html" indent="no"/>]]><![CDATA[<xsl:param name="sortCol"/>]]><![CDATA[<xsl:param name="numberFormat"/>]]><![CDATA[<xsl:param name="numberFormatMask"/>]]><![CDATA[<xsl:param name="currencySymbol"/>]]><![CDATA[<xsl:param name="colWidths"/>]]><!--
		set the number format to use for format-number() later
	--><![CDATA[<xsl:decimal-format name="us" grouping-separator="," decimal-separator="."/>]]><![CDATA[<xsl:decimal-format name="eu" grouping-separator="." decimal-separator=","/>]]><![CDATA[<xsl:decimal-format name="fr" grouping-separator=" " decimal-separator=","/>]]><![CDATA[<xsl:decimal-format name="nz" grouping-separator="'" decimal-separator="."/>]]><!--
		helper function used in the number formatting process
	--><![CDATA[<xsl:template name="replace">]]><![CDATA[<xsl:param name="source" />]]><![CDATA[<xsl:param name="oldVal" />]]><![CDATA[<xsl:param name="newVal" />]]><![CDATA[<xsl:variable name="temp" select="$source" />]]><![CDATA[<xsl:variable name="first" select="substring-before($temp, $oldVal)" />]]><![CDATA[<xsl:variable name="rest" select="substring-after($temp, $oldVal)" />]]><![CDATA[<xsl:value-of select="concat($first, $newVal)" />]]><![CDATA[<xsl:choose>]]><![CDATA[<xsl:when test="(substring-before($rest, $oldVal)) or (substring-after($rest, $oldVal))">]]><![CDATA[<xsl:call-template name="replace">]]><![CDATA[<xsl:with-param name="source" select="$rest" />]]><![CDATA[<xsl:with-param name="oldVal" select="$oldVal" />]]><![CDATA[<xsl:with-param name="newVal" select="$newVal" />]]><![CDATA[</xsl:call-template>]]><![CDATA[</xsl:when>]]><![CDATA[<xsl:otherwise>]]><![CDATA[<xsl:value-of select="$rest" />]]><![CDATA[</xsl:otherwise>]]><![CDATA[</xsl:choose>]]><![CDATA[</xsl:template>]]><![CDATA[<xsl:template match="]]><xsl:value-of select="@name" /><![CDATA[">]]><![CDATA[<table id="gridBodyTable" onmouseover="RenderToolTip();" onclick="handleClick();" ondblclick="handleDblClick();" cellspacing="0" cellpadding="1" class="gridData" oname="]]><xsl:value-of select="@object" /><![CDATA[">]]><![CDATA[<xsl:attribute name="morerecords"><xsl:choose><xsl:when test="@morerecords = 1">1</xsl:when><xsl:otherwise>0</xsl:otherwise></xsl:choose></xsl:attribute>]]><xsl:if test="@preview = 1"><!--[CDATA[<col width="20" style="padding-left:0px;"/>]]--></xsl:if><!--		
				Special case for Lead Advanced Find LayoutXml where icon=""...this should 
				be icon="1" however we can't update this till v2.0  
			--><xsl:if test="(@icon = 1 or (@icon = '' and (number(@object)=4)))"><xsl:choose><xsl:when test="@preview = 0"><![CDATA[<col width="30"/>]]></xsl:when><xsl:otherwise><![CDATA[<col width="40"/>]]><!--[CDATA[<col width="20" style="padding-left:0px;"/>]]--></xsl:otherwise></xsl:choose></xsl:if><xsl:for-each select="row/cell"><xsl:choose><xsl:when test="@width"><![CDATA[
							<col>
							<xsl:attribute name="width">
								<xsl:choose>
									<xsl:when test="$colWidths">
										<xsl:call-template name="ParseCommaDelimitedString">
											<xsl:with-param name="data" select="$colWidths"/>
											<xsl:with-param name="position" select="]]><xsl:value-of select="position()" /><![CDATA["/>
										</xsl:call-template>
									</xsl:when>
									<xsl:otherwise>]]><xsl:value-of select="@width+10" /><![CDATA[</xsl:otherwise>
								</xsl:choose>
							</xsl:attribute>]]><![CDATA[<xsl:if test="$sortCol=']]><xsl:value-of select="@name" /><![CDATA['">]]><![CDATA[<xsl:attribute name="style">background-color:#f2f2f6;</xsl:attribute>]]><![CDATA[</xsl:if>]]><![CDATA[</col>]]></xsl:when><xsl:otherwise><![CDATA[<col>]]><![CDATA[<xsl:choose>]]><![CDATA[<xsl:when test="$sortCol=']]><xsl:value-of select="@name" /><![CDATA['">]]><![CDATA[<xsl:attribute name="style">padding-left:10px;background-color:#f2f2f6;</xsl:attribute>]]><![CDATA[</xsl:when>]]><![CDATA[<xsl:otherwise>]]><![CDATA[<xsl:attribute name="style">padding-left:10px;</xsl:attribute>]]><![CDATA[</xsl:otherwise>]]><![CDATA[</xsl:choose>]]><![CDATA[</col>]]></xsl:otherwise></xsl:choose></xsl:for-each><![CDATA[<xsl:for-each select="]]><xsl:value-of select="row/@name" /><![CDATA[">]]><![CDATA[<tr>]]><![CDATA[<xsl:attribute name="oid"><xsl:value-of select="]]><xsl:value-of select="row/@id" /><![CDATA["/></xsl:attribute>]]><xsl:if test="row/@multiobjectidfield != ''"><![CDATA[<xsl:attribute name="otype"><xsl:value-of select="]]><xsl:value-of select="row/@multiobjectidfield" /><![CDATA["/></xsl:attribute>]]></xsl:if><![CDATA[<xsl:attribute name="oid"><xsl:value-of select="]]><xsl:value-of select="row/@id" /><![CDATA["/></xsl:attribute>]]><xsl:if test="@preview = 1"><!--[CDATA[<td><img src="imgs/r.gif"/></td>]]--></xsl:if><!--		
						Special case for Lead Advanced Find LayoutXml where icon=""...this should 
						be icon="1" however we can't update this till v2.0  
					--><xsl:if test="(@icon = 1 or (@icon = '' and (number(@object)=4)))"><xsl:choose><xsl:when test="row/@multiobjectidfield != ''"><![CDATA[<td align="center"><img><xsl:attribute name="src">/_imgs/ico_16_<xsl:value-of select="]]><xsl:value-of select="row/@multiobjectidfield" /><![CDATA["/>.gif</xsl:attribute></img></td>]]></xsl:when><xsl:otherwise><![CDATA[<td align="center"><img src="/_imgs/ico_16_]]><xsl:value-of select="@object" /><![CDATA[.gif"/></td>]]></xsl:otherwise></xsl:choose></xsl:if><xsl:for-each select="row/cell"><![CDATA[<td><nobr>]]><xsl:apply-templates select="." /><![CDATA[</nobr></td>]]></xsl:for-each><![CDATA[</tr>]]><![CDATA[</xsl:for-each>]]><![CDATA[</table>]]><![CDATA[</xsl:template>]]><![CDATA[
		<xsl:template name="ParseCommaDelimitedString">
			<xsl:param name="data"/>
			<xsl:param name="position"/>
			<xsl:choose>
				<xsl:when test="contains($data,',')">
					<xsl:choose>
						<xsl:when test="$position = 1">
				
							<!-- Return the first value in the string -->
							<xsl:value-of select="substring-before($data,',')"/>
			
						</xsl:when>
						<xsl:when test="$position > 1">
			
							<!-- Loop through the string until we find the n position -->
							<xsl:call-template name="ParseCommaDelimitedString">
								<xsl:with-param name="data" select="substring-after($data,',')"/>
								<xsl:with-param name="position" select="$position - 1"/>
							</xsl:call-template>
			
						</xsl:when>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>

					<!-- Return the last value in the string -->
					<xsl:value-of select="$data"/>

				</xsl:otherwise>
			</xsl:choose>
		</xsl:template>
	]]><!-- End Script Block Test --><![CDATA[</xsl:stylesheet>]]></xsl:template>
  <!--
	writes out the cell
-->
  <xsl:template match="/grid/row/cell">
    <!--
		does this cell span multiple columns?
	-->
    <xsl:param name="colspan" />
    <!--
		populate local variables
	-->
    <xsl:variable name="fieldName" select="@name" />
    <xsl:variable name="dataType" select="/grid/metadata/fields/field[@name = $fieldName]/@datatype" />
    <xsl:variable name="defaultValue" select="/grid/properties/fields/field[@name = $fieldName]/@defaultvalue" />
    <xsl:variable name="format" select="/grid/properties/fields/field[@name = $fieldName]/@format" />
    <xsl:variable name="showGrouping" select="/grid/properties/fields/field[@name = $fieldName]/@grouping" />
    <xsl:variable name="decAccuracy" select="/grid/properties/fields/field[@name = $fieldName]/@accuracy" />
    <xsl:choose>
      <!--
			Boolean and PickList datatypes
		-->
      <xsl:when test="$dataType = 'boolean' or $dataType = 'picklist' or $dataType = 'state' or $dataType = 'status'"><![CDATA[<xsl:value-of select="]]><xsl:value-of select="$fieldName" /><![CDATA[/@name"/>]]></xsl:when>
      <!--
			Lookup datatype
		-->
      <xsl:when test="$dataType = 'lookup' or $dataType = 'owner' or $dataType = 'customer'"><![CDATA[<xsl:if test="]]><xsl:value-of select="$fieldName" /><![CDATA[/@dsc = 0">]]><![CDATA[<xsl:value-of select="]]><xsl:value-of select="$fieldName" /><![CDATA[/@name"/>]]><![CDATA[</xsl:if>]]></xsl:when>
      <!--
			integer, float, and money datatypes
		-->
      <xsl:when test="$dataType = 'integer' or $dataType = 'float' or $dataType = 'money'"><![CDATA[<xsl:if test="]]><xsl:value-of select="$fieldName" /><![CDATA[">]]><xsl:if test="$dataType = 'money'"><![CDATA[<xsl:value-of select="concat($currencySymbol, ' ')"/>]]></xsl:if><!--
						numberFormatMask has the following structure "#,##0.*;0#,##0.*"
						We need to replace '*'s with the appropriate number of 0s to specify the accuracy
						For example if the accuracy is three the formatNumberPattern variable will have the value of "#,##0.000;0#,##0.000"
						If the accuracy iz zero (i.e. the number doesn't have antyhing after the decimal point)
						we convert the mask to the following form: "#,##0.#;0#,##0.#"
					--><![CDATA[<xsl:variable name="formatNumberPattern">]]><xsl:choose><xsl:when test="$decAccuracy&gt;0"><![CDATA[<xsl:call-template name="replace">]]><![CDATA[<xsl:with-param name="source" select="$numberFormatMask" />]]><![CDATA[<xsl:with-param name="oldVal" select="'*'" />]]><![CDATA[<xsl:with-param name="newVal" select="']]><xsl:value-of select="substring('0000000000', 1, $decAccuracy)" /><![CDATA['" />]]><![CDATA[</xsl:call-template>]]></xsl:when><xsl:otherwise><![CDATA[<xsl:call-template name="replace">]]><![CDATA[<xsl:with-param name="source" select="$numberFormatMask" />]]><![CDATA[<xsl:with-param name="oldVal" select="'*'" />]]><![CDATA[<xsl:with-param name="newVal" select="'#'" />]]><![CDATA[</xsl:call-template>]]></xsl:otherwise></xsl:choose><![CDATA[</xsl:variable>]]><![CDATA[<xsl:variable name="formattedNumber" select="format-number(]]><xsl:value-of select="$fieldName" /><![CDATA[, $formatNumberPattern, $numberFormat)"/>]]><!--
						replace	'~' sign with the '-' sign
						'~' is used to deal with some strange behavior of the XSLT processor when '-' is used in the pattern
					--><![CDATA[<xsl:value-of select="translate($formattedNumber, '~', '-')"/>]]><![CDATA[</xsl:if>]]></xsl:when>
      <!--
			datetime datatype
		-->
      <xsl:when test="$dataType = 'datetime'"><![CDATA[<xsl:value-of select="]]><xsl:value-of select="$fieldName" /><![CDATA[/@date"/>]]><xsl:if test="$format = 'datetime'"><![CDATA[<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text><xsl:value-of select="]]><xsl:value-of select="$fieldName" /><![CDATA[/@time"/>]]></xsl:if></xsl:when>
      <!--
			memo and text datatypes
		-->
      <xsl:when test="$dataType = 'memo' or $dataType = 'text'"><![CDATA[<xsl:value-of select="]]><xsl:value-of select="$fieldName" /><![CDATA["/>]]></xsl:when>
      <!--
			not a recognized datatype
		-->
      <xsl:otherwise>
        <xsl:value-of select="$fieldName" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>